{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#Bin Values:\n",
    "def bins(column, cutpoints, labels=None):\n",
    "  #Define min and max values:\n",
    "  min_val = column.min()\n",
    "  max_val = column.max()\n",
    "  print('Minimum value ',min_val)\n",
    "  print(' Maximum Value ',max_val)\n",
    "\n",
    "  break_points = [min_val] + cut_points + [max_val]\n",
    "\n",
    "  if not labels:\n",
    "    labels = range(len(cut_points)+1)\n",
    "\n",
    "  #Create bins using the cut function in pandas\n",
    "  column_bin = pd.cut(column,bins=break_points,labels=labels,include_lowest=True)\n",
    "  return column_bin\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(14999, 10)\n",
      "['satisfaction_level', 'last_evaluation', 'number_project', 'average_montly_hours', 'time_spend_company', 'Work_accident', 'left', 'promotion_last_5years', 'sales', 'salary']\n",
      "0.09\n",
      "1.0\n",
      "\n",
      "####The number of values in each bin are:###\n",
      "\n",
      " low       1941\n",
      "medium    4788\n",
      "high      8270\n",
      "Name: satisfaction_level, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "hr_data = pd.read_csv('data/hr.csv', header=0)\n",
    "hr_data.head()\n",
    "hr_data = hr_data.dropna()\n",
    "print(hr_data.shape)\n",
    "print(list(hr_data.columns))\n",
    "#Binning satisfaction level:\n",
    "cut_points = [0.3,0.6]\n",
    "labels = [\"low\",\"medium\",\"high\"]\n",
    "hr_data[\"satisfaction_level\"] = bins(hr_data[\"satisfaction_level\"], cut_points, labels)\n",
    "print('\\n####The number of values in each bin are:###\\n\\n',pd.value_counts(hr_data[\"satisfaction_level\"], sort=False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
